package com.hulk.dryad.manage.framework.websocket.server.handshake;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.server.ServerHttpRequest;
import org.springframework.web.socket.WebSocketHandler;
import org.springframework.web.socket.server.support.DefaultHandshakeHandler;
import org.springframework.lang.Nullable;
import java.security.Principal;
import java.util.Map;

/**
 * Principal 解析
 *
 * @author
 */
@Slf4j
public class PrincipalHandshakeHandler extends DefaultHandshakeHandler {

    @Nullable
	@Override
	protected Principal determineUser(ServerHttpRequest request, WebSocketHandler wsHandler, Map<String, Object> attributes) {
		Principal principal = (Principal) attributes.get(WebSocketAuthHandshakeInterceptor.WS_PRINCIPAL_ATTR_NAME);
		log.info("获取principal: [{}]", principal);
		return principal;
	}
}
